From: Adel Gadllah Date: Fri, 13 Sep 2013 07:33:27 +0000 (+0200) Subject: st-scroll-view-fade: Reduce number of GLSL uniforms and instructions X-Git-Tag: archive/raspbian/50.5-1+rpi1~1^2~1013^2^2~3429 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=4095a58eb9a2921c178b30c56d1fbe7662c2778a;p=gnome-shell.git st-scroll-view-fade: Reduce number of GLSL uniforms and instructions The vvalue and hvalue uniforms are only used to decide whether we should do fade the edges or not based on the fade_edges uniform. The result does not change accross fragments so there is no reason to recompute it for every fragment (pixel) so just split the edge fade into two uniforms and compute the "should we fade the edges" boolean once for every direction (when setting the uniforms) instead of for every single fragment twice. This reduces the number of uniforms as well as the the number of instructions which are limited on older hardware. It should also be more efficent. https://bugzilla.gnome.org/show_bug.cgi?id=708007 --- diff --git a/src/st/st-scroll-view-fade.c b/src/st/st-scroll-view-fade.c index 3c0c26bce..9f267c3b6 100644 --- a/src/st/st-scroll-view-fade.c +++ b/src/st/st-scroll-view-fade.c @@ -142,18 +142,17 @@ st_scroll_view_fade_paint_target (ClutterOffscreenEffect *effect) st_adjustment_get_values (self->vadjustment, &value, &lower, &upper, NULL, NULL, &page_size); value = (value - lower) / (upper - page_size - lower); - clutter_shader_effect_set_uniform (shader, "vvalue", G_TYPE_FLOAT, 1, value); + clutter_shader_effect_set_uniform (shader, "fade_edges_v", G_TYPE_INT, 1, self->fade_edges ? value >= 0.0 : value > 0.0); st_adjustment_get_values (self->hadjustment, &value, &lower, &upper, NULL, NULL, &page_size); value = (value - lower) / (upper - page_size - lower); - clutter_shader_effect_set_uniform (shader, "hvalue", G_TYPE_FLOAT, 1, value); + clutter_shader_effect_set_uniform (shader, "fade_edges_h", G_TYPE_INT, 1, self->fade_edges ? value >= 0.0 : value > 0.0); clutter_shader_effect_set_uniform (shader, "vfade_offset", G_TYPE_FLOAT, 1, self->vfade_offset); clutter_shader_effect_set_uniform (shader, "hfade_offset", G_TYPE_FLOAT, 1, self->hfade_offset); clutter_shader_effect_set_uniform (shader, "tex", G_TYPE_INT, 1, 0); clutter_shader_effect_set_uniform (shader, "height", G_TYPE_FLOAT, 1, clutter_actor_get_height (self->actor)); clutter_shader_effect_set_uniform (shader, "width", G_TYPE_FLOAT, 1, clutter_actor_get_width (self->actor)); - clutter_shader_effect_set_uniform (shader, "fade_edges", G_TYPE_INT, 1, self->fade_edges); clutter_shader_effect_set_uniform (shader, "fade_area_topleft", CLUTTER_TYPE_SHADER_FLOAT, 2, fade_area_topleft); clutter_shader_effect_set_uniform (shader, "fade_area_bottomright", CLUTTER_TYPE_SHADER_FLOAT, 2, fade_area_bottomright); diff --git a/src/st/st-scroll-view-fade.glsl b/src/st/st-scroll-view-fade.glsl index 629c0143d..23881fb97 100644 --- a/src/st/st-scroll-view-fade.glsl +++ b/src/st/st-scroll-view-fade.glsl @@ -22,9 +22,8 @@ uniform float height; uniform float width; uniform float vfade_offset; uniform float hfade_offset; -uniform float vvalue; -uniform float hvalue; -uniform bool fade_edges; +uniform bool fade_edges_h; +uniform bool fade_edges_v; uniform vec2 fade_area_topleft; uniform vec2 fade_area_bottomright; @@ -45,14 +44,10 @@ void main () float ratio = 1.0; float fade_bottom_start = fade_area_bottomright[1] - vfade_offset; float fade_right_start = fade_area_bottomright[0] - hfade_offset; - bool fade_top = y < vfade_offset && (fade_edges ? vvalue >= 0.0 - : vvalue > 0.0); - bool fade_bottom = y > fade_bottom_start && (fade_edges ? vvalue <= 1.0 - : vvalue < 1.0); - bool fade_left = x < hfade_offset && (fade_edges ? hvalue >= 0.0 - : hvalue > 0.0); - bool fade_right = x > fade_right_start && (fade_edges ? hvalue <= 1.0 - : hvalue < 1.0); + bool fade_top = y < vfade_offset && fade_edges_v; + bool fade_bottom = y > fade_bottom_start && fade_edges_v; + bool fade_left = x < hfade_offset && fade_edges_h; + bool fade_right = x > fade_right_start && fade_edges_h; float vfade_scale = height / vfade_offset; if (fade_top) {